<template>
	<view class="flex-column  page">

		<custom-navigation title="搭配套餐/组合商品">
		</custom-navigation>
		<view class="add-goods-btn flex-row-center" @click="$navigateTo('/pages/goods/goods_info?selectMode=true')">
			<image src="../../static/folder.png"></image>
			<text>添加商品</text>
		</view>
		<view class="body flex-row">
			<scroll-view class="t-scrooll" scroll-y="true">
				<view class="vip-price-box flex-column">
					<view class="flex-row">
						<view class="item1">商品名称</view>
						<view class="item1" @click="showPop=true">数量<text class="hint"><br />（批量设置）</text></view>
						<view class="item1"> 操作</view>
					</view>
					<view class="flex-row" v-for="(item,index) in goodsList" :key="item.id">
						<view class="item1 text-line-1">{{item.goods_name}}</view>
						<input placeholder-class="input-hint" placeholder="请输入" v-model="item.goods_num" />
						<view class="deltext flex-column-center" @click="delGoods(index)">删除</view>
					</view>
					<view class="empty" v-if="goodsList.length==0">暂无商品</view>
				</view>
				<alert message="批量设置" :isInput="true" :show="showPop" @leftAction="showPop=false" @rightAction="confirm">
				</alert>
			</scroll-view>
		</view>
		<view class="bottom flex-column-center">
			<view class="btn" @click="confirmSelect">保存</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsList: [],
				showPop: false
			}
		},
		onShow() {
			try {
				let list = uni.getStorageSync("setMealGoodsList")
				if (list != null) {
					this.goodsList.push(...list)
					uni.setStorageSync("setMealGoodsList", null)
				}
				
				list = uni.getStorageSync("multipleSelectList")
				if (list != null) {
					this.goodsList.push(...list)
					uni.setStorageSync("multipleSelectList", null)
				}
			} catch (error) {
				console.error(error);
			}
		},
		methods: {
			confirmSelect() {
				if( this.goodsList.length==0){
					uni.showToast({
						title:"请添加商品",
						icon:'none'
					})
				}
				for(let i in this.goodsList){
					if(this.goodsList[i].goods_num==undefined||this.goodsList[i].goods_num.length==0){
						uni.showToast({
							title:"请输入数量",
							icon:'none'
						})
						return;
					}
					 
				}
				uni.setStorageSync("setMealGoodsList",this.goodsList)
				uni.navigateBack()
			},
			confirm(value) {
				for (let i in this.goodsList) {
					this.goodsList[i].goods_num = value
				}
				this.showPop = false
			},
			delGoods(index) {
				this.goodsList.splice(index, 1)
			},
			addGoods() {
				uni.navigateTo({
					url: '/pages/goods/goods_info?selectMode=true'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.body {
		flex: 1;
		height: 1rpx;
		background-color: #f8f8f8;
		overflow: hidden;
	}
	.t-scrooll{
		border-top: 1px solid transparent;
	}
	.bottom {
		width: 100%;
		height: 130rpx;
		justify-content: center;
		opacity: 1;
		background: #f8f8f8;
		z-index: 1;
		.btn {
			width: 320rpx;
			height: 80rpx;
			opacity: 1;
			border-radius: 40px;
			background: rgba(56, 192, 158, 1);
			font-size: 32rpx;
			font-weight: 700;
			line-height: 80rpx;
			text-align: center;
			color: rgba(255, 255, 255, 1);
		}
	}
	.add-goods-btn {
		margin-left: 24rpx;
		margin-top: 20rpx;
		margin-bottom: 22rpx;
		width: 222rpx;
		height: 80rpx;
		line-height: 80rpx;
		opacity: 1;
		z-index: 1000;
		border-radius: 50rpx;
		border: 2px solid rgba(56, 192, 158, 1);
		justify-content: center;

		image {
			width: 40rpx;
			height: 40rpx;
			margin-right: 8rpx;
		}

		text {
			font-size: 30rpx;
			font-weight: 700;
			color: rgba(56, 192, 158, 1);
		}

	}

	.empty {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background: rgba(255, 255, 255, 1);
		border: 1px solid rgba(207, 207, 207, 1);
		text-align: center;

	}

	.vip-price-box {
		margin: 0 28rpx 32rpx 28rpx;
		background-color: rgba(207, 207, 207, 1);
		box-sizing: content-box;
		border-right: 1rpx solid rgba(207, 207, 207, 1);
		border-bottom: 1rpx solid rgba(207, 207, 207, 1);

		.item1 {
			flex: 1;
			padding: 20rpx 0;
			line-height: 28rpx;
			width: 100%;
			text-align: center;
			font-size: 30rpx;
			font-weight: 700;
			color: rgba(0, 0, 0, 1);
			background-color: white;
			margin: 1rpx;

			.hint {
				font-size: 24rpx;
				font-weight: 500;
				color: rgba(153, 153, 153, 1);
			}
		}

		input {
			flex: 1;
			text-align: center;
			color: rgba(51, 51, 51, 1);
			font-size: 30rpx;
			min-height: 80rpx;
			font-weight: 500;
			background-color: white;
			margin: 1rpx;
		}

		.input-hint {
			font-size: 28rpx;
			font-weight: 500;
			padding: 20rpx 0;
			line-height: 40rpx;
			text-align: center;
			color: rgba(153, 153, 153, 1);
		}

		.deltext {
			margin: 1rpx;
			justify-content: center;
			flex: 1;
			font-size: 28rpx;
			font-weight: 500;
			background-color: white;
			color: rgba(56, 192, 158, 1);
		}
	}
</style>
